package com.ruoyi.api.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.api.domain.BizPhone;
import com.ruoyi.api.service.IBizPhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 电话设备Controller
 * 
 * @author 魏建波
 * @date 2022-01-21
 */
@RestController
@RequestMapping("/api2/phone")
public class BizPhoneController extends BaseController
{
    @Autowired
    private IBizPhoneService bizPhoneService;

    /**
     * 查询电话设备列表
     */
    @PreAuthorize("@ss.hasPermi('api:phone:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizPhone bizPhone)
    {
        startPage();
        List<BizPhone> list = bizPhoneService.selectBizPhoneList(bizPhone);
        return getDataTable(list);
    }

    /**
     * 导出电话设备列表
     */
    @PreAuthorize("@ss.hasPermi('api:phone:export')")
    @Log(title = "电话设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizPhone bizPhone)
    {
        List<BizPhone> list = bizPhoneService.selectBizPhoneList(bizPhone);
        ExcelUtil<BizPhone> util = new ExcelUtil<BizPhone>(BizPhone.class);
        util.exportExcel(response, list, "电话设备数据");
    }

    /**
     * 获取电话设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('api:phone:query')")
    @GetMapping(value = "/{phoneId}")
    public AjaxResult getInfo(@PathVariable("phoneId") Long phoneId)
    {
        return AjaxResult.success(bizPhoneService.selectBizPhoneByPhoneId(phoneId));
    }

    /**
     * 新增电话设备
     */
    @PreAuthorize("@ss.hasPermi('api:phone:add')")
    @Log(title = "电话设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizPhone bizPhone)
    {
        return toAjax(bizPhoneService.insertBizPhone(bizPhone));
    }

    /**
     * 修改电话设备
     */
    @PreAuthorize("@ss.hasPermi('api:phone:edit')")
    @Log(title = "电话设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizPhone bizPhone)
    {
        return toAjax(bizPhoneService.updateBizPhone(bizPhone));
    }

    /**
     * 删除电话设备
     */
    @PreAuthorize("@ss.hasPermi('api:phone:remove')")
    @Log(title = "电话设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{phoneIds}")
    public AjaxResult remove(@PathVariable Long[] phoneIds)
    {
        return toAjax(bizPhoneService.deleteBizPhoneByPhoneIds(phoneIds));
    }
}
